{extend name="../../base/view/common/base" /}
{block name="style"}
<style>
.layui-form-pane .layui-form-label {width:60px; padding:8px;}
.layui-form-pane .layui-form-label.label-index,.layui-form-pane .layui-form-label.label-first {width:80px;}
.layui-form-item .layui-input-inline {margin-right:4px;}
.layui-form-item .layui-inline {margin-right:0; margin-bottom:0;}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-3">
	<h3 class="pb-3">编辑项目阶段</h3>
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray">项目名称<font>*</font></td>
			<td>{$detail.name}</td>
			<td class="layui-td-gray-2">计划完成周期</td>
			<td>{$detail.start_time_str} - {$detail.end_time_str}</td>
		</tr>
		<tr>
			<td class="layui-td-gray">负责人</td>
			<td>{$detail.director_name}</td>
			<td class="layui-td-gray">项目成员</td>
			<td>{$detail.team_admin_names}</td>
		</tr>
		{gt name="$detail.contract_id" value="0"}
		<tr>
			<td class="layui-td-gray">关联合同</td>
			<td colspan="3">{$detail.contract}</td>
		</tr>
		{/gt}
		<tr>
			<td class="layui-td-gray">项目简介</td>
			<td colspan="3">{$detail.content}</td>
		</tr>
		<tr>
			<td colspan="4"><strong>项目阶段</strong><span style="color: red">*</span></td>
		</tr>
		<tr>
			<td colspan="4">
				<table id="flowList" class="layui-table layui-table-min" style="margin:0">
					<tr>
						<th width="60">序号</th>
						<th width="200">阶段名称</th>
						<th width="80">阶段负责人</th>
						<th>阶段成员</th>
						<th width="162">阶段周期</th>
						<th width="60">操作</th>
					</tr>
					{volist name="$step_array" id="vo"}
					<tr class="step-tr">
						<td class="step-key">第 <strong>{$key+1}</strong> 阶段</td>
						<td><input type="text" name="flowName[]" value="{$vo.flow_name}" class="layui-input" lay-verify="required" lay-reqText="请输入阶段名称"></td>
						{egt name="$key" value="$detail.step_sort"}
						<td>
							<input type="text" value="{$vo.check_name}" class="layui-input layui-input-readonly picker-one" lay-verify="required" lay-reqText="请选择负责人" readonly>
							<input type="hidden" name="chargeIds[]" value="{$vo.flow_uid}" readonly>
						</td>
						{else/}
						<td>
							{$vo.check_name}
							<input type="hidden" name="chargeIds[]" value="{$vo.flow_uid}" readonly>
						</td>
						{/egt}
						<td>
							<input type="text" value="{$vo.flow_names}" class="layui-input layui-input-readonly picker-more">
							<input type="hidden" name="membeIds[]" value="{$vo.flow_ids}">
						</td>
						<td><input type="text" name="cycleDate[]" value="{$vo.start_time} 到 {$vo.end_time}" class="layui-input select-time-range" lay-verify="required" lay-reqText="请选择阶段周期" readonly></td>
						<td width="60">-<input type="hidden" name="step_id[]" value="{$vo.id}"></td>
					</tr>
					{/volist}
				</table>
				<div class="pt-2">
					<span class="layui-btn layui-btn-sm add-flow">+ 添加阶段</span>
				</div>
				<div style="padding:10px; margin-top:10px; font-size:12px; background-color:#fffcf0">
					<p><strong>温馨提示</strong></p>
					<p>1、项目开始流转前，请确保已完善好各项目信息。</p>
					<p>2、项目开始流转后，只有项目管理员，创建人和负责人可修改项目信息。</p>
					<p>3、项目管理员，创建人和负责人可以修改阶段的信息。</p>
				</div>
			</td>
		</tr>
	</table>
	<div class="pt-3">
		<input type="hidden" name="id" value="{$detail.id}" />
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','employeepicker'];
	function gouguInit() {
		var form = layui.form,tool = layui.tool,laydate = layui.laydate,employeepicker = layui.employeepicker;		
		//日期
		lay('.select-time-range').each(function () {
			laydate.render({
				elem: this,
				range: '到',
				trigger: 'click'
			});
		});
		
		$('.add-flow').on('click',function(){
			let len = $('#flowList').find('.step-tr').length;
			let index = len+1;
			let tem='<tr class="step-tr">\
						<td class="step-key">第 <strong>'+index+'</strong> 阶段</td>\
						<td><input type="text" name="flowName[]" value="" class="layui-input" lay-verify="required" lay-reqText="请输入阶段名称"></td>\
						<td>\
							<input type="text" value="" class="layui-input layui-input-readonly picker-one" lay-verify="required" lay-reqText="请选择负责人" readonly>\
							<input type="hidden" name="chargeIds[]" value="0" readonly>\
						</td>\
						<td>\
							<input type="text" value="" class="layui-input layui-input-readonly picker-more">\
							<input type="hidden" name="membeIds[]" value="">\
						</td>\
						<td><input type="text" name="cycleDate[]" value="" class="layui-input select-time-range" data-range="到" lay-verify="required" lay-reqText="请选择阶段周期" readonly></td>\
						<td>\
							<input type="hidden" name="step_id[]" value="0" class="layui-input">\
							<span class="layui-btn layui-btn-danger layui-btn-sm">删除</span>\
						</td>\
					</tr>';
			$('#flowList').append(tem);
			form.render();
			//日期
			lay('.select-time-range').each(function () {
				laydate.render({
					elem: this,
					range: '到',
					trigger: 'click'
				});
			});
		});
		$('#flowList').on('click','.layui-btn-danger',function(){
			var items = $('.step-tr').length;
			if(items>1){
				$(this).parents('tr.step-tr').remove();
				$('.step-key').each(function(index,item){
					$(this).html('第'+(index+1)+'阶段');
				})
			}
			else{
				layer.msg('至少保留一个阶段');
			}
		});
		
		//监听提交
		form.on('submit(webform)', function (data) {
			layer.confirm('确认重置项目阶段信息？', {
				icon: 3,
				title: '温馨提示'
			}, function(index) {
				let callback = function (e) {
					layer.msg(e.msg);
					if (e.code == 0) {
						tool.sideClose(1000);
					}
				}
				tool.post("/project/api/reset_check",data.field,callback);
				layer.close(index);
			});			
			return false;
		});
	}

</script>
{/block}